import unittest

from Finance_fun.page.page02_login import Page_Login
from Finance_fun.base.get_driver import GetDriver
from Finance_fun.tool.read_json import read_json
from parameterized import parameterized
from Finance_fun.tool import assert_rl


def get_login_data():
    case = read_json("data02_login_case.json")
    list_null = []
    for data in case.values():
        list_null.append(
            (
                data["phone"],
                data["password"],
                data["expect"]
             )
        )
    return list_null

print(get_login_data())

class LoginTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = GetDriver.get_driver()
        cls.login = Page_Login(cls.driver)
        cls.login.page_click_login_link()

    @classmethod
    def tearDownClass(cls):
        GetDriver.quit_driver()

    @parameterized.expand(get_login_data())
    def test_login(self, phone, password,expect):
        print(self.login.isElementExist())
        if self.login.isElementExist() == True:
            self.login.page_login_pwd_err(phone,password,"8888")
            assert_rl.assert_login_success(self, expect)
        else:
            self.login.page_login(phone, password)
            if expect in "登录成功":
                assert_rl.assert_login_success(self, expect)
                self.tearDownClass()
                self.setUpClass()
            else:
                assert_rl.assert_login_error(self, expect)
